package zhongbo.java.air.monitor.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.monitor.mapper.FlightActivityDailyMapper;
import zhongbo.java.air.monitor.model.FlightActivityDaily;
import zhongbo.java.air.monitor.service.IFlightActivityDailyService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 说明：
 *
 * @author 钟波dellNotebook
 * @since 2025年04月08日 星期二 04:07:41
 */
@Service
@Slf4j
public class FlightActivityDailyServiceImpl implements IFlightActivityDailyService {

    @Autowired
    private FlightActivityDailyMapper flightActivityDailyMapper;

    @Override
    public List<FlightActivityDaily> selectDailyStats(String date) {
        return flightActivityDailyMapper.selectDailyStats(date);
    }

    @Override
    public List<FlightActivityDaily> getDailyStats(String date) {
        if (StrUtil.isBlank(date)) {
            throw new RuntimeException("data参数必须填写!示例: 2025-04-08");
        }
        List<FlightActivityDaily> flightActivityDailies = flightActivityDailyMapper.selectDailyStats(date);
        // todo 根据 date 条件, 从 air_flight_activity_daily 表里查询结果,并返回
        return flightActivityDailies;
    }

    @Override
    public int addFlightActivityDaily(FlightActivityDaily flightActivityDaily) {
       flightActivityDaily.setId(null);
       if (flightActivityDaily == null || flightActivityDaily.equals("")){
           throw new RuntimeException("NULL");
       }
        int insert = flightActivityDailyMapper.insert(flightActivityDaily);
        return insert;
    }

    @Override
    public void deleteFlightActivityDaily(String id) {
        if (id == null || id.equals("")){
            throw new RuntimeException("NULL");
        }
        FlightActivityDaily flightActivityDaily = flightActivityDailyMapper.selectById(id);
        if (flightActivityDaily != null) {
            flightActivityDailyMapper.deleteById(id);
        }else {
            throw new RuntimeException("无该数据");
        }
    }

    @Override
    public int updateFlightActivityDaily(FlightActivityDaily flightActivityDaily) {
        if (flightActivityDaily == null || flightActivityDaily.equals("")){
            throw new RuntimeException("NULL");
        }
        int update = flightActivityDailyMapper.updateById(flightActivityDaily);
        return update;
    }

    @Override
    public FlightActivityDaily selectById(String id) {
        if (id == null || id.equals("")){
            throw new RuntimeException("NULL");
        }
        FlightActivityDaily flightActivityDaily = flightActivityDailyMapper.selectById(id);
        return flightActivityDaily;
    }

    @Override
    public PageVo page(String date, Integer pageNumber, Integer pageSize) {
        QueryWrapper<FlightActivityDaily> queryWrapper = new QueryWrapper<>();
        if (date !=null){
            queryWrapper.eq("date",date);
        }
        IPage<FlightActivityDaily> pageParam = new Page<>(pageNumber,pageSize);
        IPage<FlightActivityDaily> pathPage =flightActivityDailyMapper.selectPage(pageParam,queryWrapper);
        return new PageVo<>(pathPage);
    }
}
